package controllers

import (
	"lsis/models"

	"github.com/astaxie/beego"
)

type StoreController struct {
	BaseController
}

func (s *StoreController) URLMapping() {
	s.Mapping("query", s.Query)
	s.Mapping("queryDetail", s.QueryStoreDetail)
}

// @Title 浏览门店
// @Description 浏览门店列表
// @Param   location   formData   string  true       "用户当前坐标,如:22.676114,113.9048777"
// @Param   session    formData   string  true       "session"
// @Success 200 {object}  models.StoreJson true      "门店信息 数组"
// @Failure 400
// @Failure 404
// @router /query [post]
func (s *StoreController) Query() {

	location := s.GetString("location")

	actives, err := models.QueryStores(s.user.Id, location)
	if err != nil {
		beego.Error("get actives failed:", err)
		s.returnResult(errCodeGetActive, err.Error(), "")
	} else {
		s.returnResult(0, "success", actives)
	}
}

// @Title 门店详情
// @Description 浏览门店列表
// @Param   location   formData   string  true       "用户当前坐标,如:22.676114,113.9048777"
// @Param   session    formData   string  true       "session"
// @Param   storeId    formData   int  true       	"门店Id"
// @Success 200 {object}  models.StoreDetail true   "门店详情"
// @Failure 400
// @Failure 404
// @router /queryDetail [post]
func (s *StoreController) QueryStoreDetail() {

	storid, err := s.GetInt("storeId")
	if err != nil {
		beego.Error("get store id failed:", err)
		s.returnResult(errCodeStore, err.Error(), "")
		return
	}
	result, err := models.QueryStoresDetail(storid)
	if err != nil {
		beego.Error("get store detail failed:", err)
		s.returnResult(errCodeStore, err.Error(), "")
		return
	}
	s.returnResult(0, "success", result)
	return
}
